import os
def cal_file_size(file):
    file_size=os.path.getsize(file)
    print("the file {} size is:{}".format(file,file_size))
    return file_size

def cal_dir_size(dir):
    files=os.listdir(dir)
    total_size=0
    for f in files:
        file = os.path.join(dir, f)
        if os.path.isfile(file):#此处是file1不是f
           size=cal_file_size(file)
           total_size += size
        if os.path.isdir(file):
            dir_size=cal_dir_size(file)
            total_size+=dir_size;
    return total_size


if __name__ == "__main__":
    print("="*40)
    total_size = 0
    total_size=cal_dir_size("./data")
    print("="*40)
    print("The dir size is:%d"%(total_size))